from model.uml_element import UmlElement
from model.uml_package_import import UmlPackageImport
from model.uml_class import UmlClass
from model.uml_association import UmlAssociation
from model.uml_enumeration import UmlEnumeration
from model.uml_data_type import UmlDataType
from model.uml_xmi_info import UmlXmiInfo


class UmlPackage(UmlElement):

    def __init__(self) -> None:
        super().__init__(UmlXmiInfo.type_package)
        self.name: str = ""
        self.uri: str = ""
        self.packageImports: list[UmlPackageImport] = []
        self.packagedElements: dict[
            str, UmlPackage | UmlClass | UmlEnumeration | UmlAssociation | UmlDataType
        ] = {}

    def to_json(self) -> dict[str, object]:
        json: dict = super().to_json()
        json["name"] = self.name
        json["uri"] = self.uri

        if self.ownedComment is not None:
            json["ownedComment"] = self.ownedComment.to_json()

        item = []
        for value in self.packageImports:
            item.append(value.to_json())
        json["packageImports"] = item

        item = {}
        for key, value in self.packagedElements.items():
            item[key] = value.to_json()
        json["packagedElements"] = item

        return json